package main

import (
	"fmt"
	"net"
)

func main() {
	udpAddr, _ := net.ResolveUDPAddr("udp", ":8888")
	conn, _ := net.ListenUDP("udp", udpAddr)
	defer conn.Close()
	for {
		buffer := make([]byte, 1024)
		n, remoteAddr, _ := conn.ReadFromUDP(buffer)
		fmt.Println("received from " + remoteAddr.String() + " : " + string(buffer[:n]))
		sendBack := "send back: " + string(buffer[:n])
		conn.WriteToUDP([]byte(sendBack), remoteAddr)
	}
}
